package uz.edo.db.manager;

import uz.edo.db.bean.Department;
import uz.edo.db.bean.User;
import uz.edo.db.manager.core.DBManager;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: said
 * Date: 1/16/12
 * Time: 9:48 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserManager extends DBManager {

    private static UserManager instance = new UserManager();

    public static UserManager getInstance() {
        return instance;
    }

    public UserManager() {
        super(User.class);
    }

    public User getUser(String userName, String password) throws Exception {
        return (User)createQuery("from User e where e.userName = :userName and e.password = :password")
                .setParameter("userName",userName)
                .setParameter("password",password)
                .uniqueResult();
    }

    public List<User> getUsers(Department department) throws Exception {
        return createQuery("from User e where e.department = :department")
                .setParameter("department", department).list();
    }

    public User afeesa(String login) throws Exception {
        return (User)createQuery("from User e where e.userName = :a").setParameter("a", login).uniqueResult();
    }

    public Integer getCount(String userName) throws Exception {
        return (Integer)createSqlQuery("select count(*) from users where ").uniqueResult();
    }
}
